import {Recordable} from "./type";

/**
 * determine if the key is a property
 * @param key
 */
export function isProperty(key: string): boolean {
    return key !== "children" && !isEvent(key);
}

/**
 * determine oldFiber and newFiber is same type
 * @param oldFiber
 * @param newFiber
 */
export function isSameType(oldFiber: any, newFiber: any) {
    return oldFiber && newFiber && newFiber.type === oldFiber.type
}

/**
 * determine if the key is a new property or new property value
 * @param oldProps
 * @param newProps
 */
export function isNewProps(oldProps: Recordable, newProps: Recordable) {
    return (key: string) => oldProps[key] !== newProps[key]
}

/**
 * determine if the key is a gone property
 * @param oldProps
 * @param newProps
 */
export function isGoneProps(oldProps: Recordable, newProps: Recordable) {
    return (key: string) => !(key in newProps)
}


/**
 * determine if the key is an event
 * @param key
 */
export function isEvent(key: string) {
    return key.startsWith("on");
}
